import { View } from "../../../../mvc/core/View";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { GuildEventName } from "../GuildEventName";
import { ResouceConst } from "../../../../component/gconst/ResouceConst";
import { ImagesConst } from "../../../resource/ImagesConst";
import { Language } from "../../../../../extend/language/Language";
import { TilePanel } from "../../equipment/TilePanel";
import { BuildingItemRender } from "./BuildingItemRender";
import { ScrollPolicy } from "../../../../../fl/controls/ScrollPolicy";
import { HallDetailPanel } from "./HallDetailPanel";
import { ObjCreate } from "../../common/ObjCreate";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { DataProvider } from "../../../../../fl/data/DataProvider";
import { SGuildStructureInfo } from "../../../../../Message/Game/SGuildStructureInfo";
import { DataEvent } from "../../../events/DataEvent";
import { EGuildStructureType } from "../../../../../Message/Public/EGuildStructureType";
import { PasturePanel } from "./PasturePanel";
import { SchoolPanel } from "./SchoolPanel";
import { AnimalPanel } from "./AnimalPanel";
import { CashboxDetailPanel } from "./CashboxDetailPanel";
import { WarehouseDetailPanel } from "./WarehouseDetailPanel";
import { ShopDetailPanel } from "./ShopDetailPanel";
import { AuraTreePanel } from "./AuraTreePanel";
import { ScaleBitmap } from "../../../../../com/mui/display/ScaleBitmap";
type int = number;
//class ManorInfoPanel
    
    export  class ManorInfoPanel extends View
    {
        constructor()
        {
            super();
            this.init();
            Dispatcher.addEventListener(GuildEventName.SelectedBuilding, this.onSelectedBuildingHandler);
            return;
        }

        /* internal  */init(): void
        {
            this._listBg = ResouceConst.getScaleBitmap(ImagesConst.WindowCenterB);
            this._listBg.width = 150;
            this._listBg.height = 380;
            this._listBg.y = 5;
            this.addChild(this._listBg);
            this._buildingNumTip = new Object /* flash.text.TextField */();
            this._buildingNumTip = new Object /* flash.text.TextField */();
            this._buildingNumTip.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._buildingNumTip.textColor = 16645324;
            this._buildingNumTip.text = Language.getString(57114);
            this._buildingNumTip.x = 15;
            this._buildingNumTip.y = 7;
            this.addChild(this._buildingNumTip);
            this._buildingListPanel = new TilePanel();
            this._buildingListPanel.styleName = "GScrollPane";
            this._buildingListPanel.verticalScrollBar.x = 128;
            this._buildingListPanel.verticalScrollBar.y = 5;
            this._buildingListPanel.setSize(140, 345);
            this._buildingListPanel.columnWidth = 130;
            this._buildingListPanel.rowHeight = 25;
            this._buildingListPanel.setStyle("cellRenderer", BuildingItemRender);
            this._buildingListPanel.x = 5;
            this._buildingListPanel.y = 33;
            this._buildingListPanel.scrollPolicy = ScrollPolicy.ON;
            this._buildingListPanel.drawNow();
            this.addChild(this._buildingListPanel);
            this._hallPanel = new HallDetailPanel();
            this._hallPanel.x = 155;
            this._hallPanel.y = 5;
            this.setMainPanel(this._hallPanel);
            this._descText = ObjCreate.createTextField(Language.getString(57115), 10, 387, 550, 20, this, GlobalStyle.textFormat6);
            return;
        }

        public setMainPanel(arg1: View): void
        {
            this._mainView = arg1;
            if (this._backupView && this.contains(this._backupView)) 
            {
                this.removeChild(this._backupView);
            }
            this._mainView.x = 155;
            this._mainView.y = 5;
            this.addChild(this._mainView);
            this._backupView = this._mainView;
            return;
        }

        public updateBuildingList(arg1: Array<any>): void
        {
            var loc2=null;
            var loc3=0;
            var loc1=new DataProvider();
            if (arg1 && arg1.length > 0) 
            {
                loc3 = 0;
                while (loc3 < arg1.length) 
                {
                    loc2 = arg1[loc3] as SGuildStructureInfo;
                    loc1.addItem(loc2);
                    ++loc3;
                }
            }
            this._buildingListPanel.dataProvider = loc1;
            if (arg1) 
            {
                this.updateBuildingNumTip(arg1.length);
                this._hallPanel.updateBuildInfoPanel(arg1[0]);
                this._buildingListPanel.selectedIndex = 0;
            }
            return;
        }

        /* internal  */updateBuildingNumTip(arg1: int): void
        {
            this._buildingNumTip.text = Language.getStringByParam(57116, arg1);
            return;
        }

        /* internal  */onSelectedBuildingHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data as SGuildStructureInfo;
            this._structureInfo = loc1;
            if (loc1) 
            {
                if (loc1.type.value() != EGuildStructureType._EGuildHall) 
                {
                    if (loc1.type.value() != EGuildStructureType._EGuildTree) 
                    {
                        if (loc1.type.value() != EGuildStructureType._EGuildShop) 
                        {
                            if (loc1.type.value() != EGuildStructureType._EGuildWareHouse) 
                            {
                                if (loc1.type.value() != EGuildStructureType._EGuildBank) 
                                {
                                    if (loc1.type.value() != EGuildStructureType._EGuildAltar) 
                                    {
                                        if (loc1.type.value() != EGuildStructureType._EGuildSchool) 
                                        {
                                            if (loc1.type.value() == EGuildStructureType._EGuildPasture) 
                                            {
                                                if (this._pasturePanel == null) 
                                                {
                                                    this._pasturePanel = new PasturePanel();
                                                }
                                                this.setMainPanel(this._pasturePanel);
                                                this._pasturePanel.updateBuildInfoPanel(loc1);
                                            }
                                        }
                                        else 
                                        {
                                            if (this._schoolPanel == null) 
                                            {
                                                this._schoolPanel = new SchoolPanel();
                                            }
                                            this.setMainPanel(this._schoolPanel);
                                            this._schoolPanel.updateBuildInfoPanel(loc1);
                                        }
                                    }
                                    else 
                                    {
                                        if (this._animalPanel == null) 
                                        {
                                            this._animalPanel = new AnimalPanel();
                                        }
                                        this.setMainPanel(this._animalPanel);
                                        this._animalPanel.updateBuildInfoPanel(loc1);
                                    }
                                }
                                else 
                                {
                                    if (this._cashboxPanel == null) 
                                    {
                                        this._cashboxPanel = new CashboxDetailPanel();
                                    }
                                    this.setMainPanel(this._cashboxPanel);
                                    this._cashboxPanel.updateBuildInfoPanel(loc1);
                                }
                            }
                            else 
                            {
                                if (this._warehousePanel == null) 
                                {
                                    this._warehousePanel = new WarehouseDetailPanel();
                                }
                                this.setMainPanel(this._warehousePanel);
                                this._warehousePanel.updateBuildInfoPanel(loc1);
                            }
                        }
                        else 
                        {
                            if (this._shopPanel == null) 
                            {
                                this._shopPanel = new ShopDetailPanel();
                            }
                            this.setMainPanel(this._shopPanel);
                            this._shopPanel.updateBuildInfoPanel(loc1);
                        }
                    }
                    else 
                    {
                        if (this._treePanel == null) 
                        {
                            this._treePanel = new AuraTreePanel();
                        }
                        this.setMainPanel(this._treePanel);
                        this._treePanel.updateBuildInfoPanel(loc1);
                    }
                }
                else 
                {
                    this.setMainPanel(this._hallPanel);
                    this._hallPanel.updateBuildInfoPanel(loc1);
                }
            }
            return;
        }

        public updateBuidingInfo(arg1: EGuildStructureType, arg2: number=0, arg3: Boolean=false): void
        {
            var loc1=0;
            if (this._structureInfo) 
            {
                if (arg3) 
                {
                    this._structureInfo.level = this._structureInfo.level + 1;
                }
                this._structureInfo.leftTime = arg2;
                if (arg1.value() != EGuildStructureType._EGuildHall) 
                {
                    if (arg1.value() != EGuildStructureType._EGuildTree) 
                    {
                        if (arg1.value() != EGuildStructureType._EGuildShop) 
                        {
                            if (arg1.value() != EGuildStructureType._EGuildWareHouse) 
                            {
                                if (arg1.value() != EGuildStructureType._EGuildAltar) 
                                {
                                    if (arg1.value() != EGuildStructureType._EGuildSchool) 
                                    {
                                        if (arg1.value() == EGuildStructureType._EGuildPasture) 
                                        {
                                            if (this._pasturePanel) 
                                            {
                                                this._pasturePanel.updateBuildInfoPanel(this._structureInfo);
                                            }
                                        }
                                    }
                                    else if (this._schoolPanel) 
                                    {
                                        this._schoolPanel.updateBuildInfoPanel(this._structureInfo);
                                    }
                                }
                                else if (this._animalPanel) 
                                {
                                    this._animalPanel.updateBuildInfoPanel(this._structureInfo);
                                }
                            }
                            else if (this._warehousePanel) 
                            {
                                this._warehousePanel.updateBuildInfoPanel(this._structureInfo);
                            }
                        }
                        else if (this._shopPanel) 
                        {
                            this._shopPanel.updateBuildInfoPanel(this._structureInfo);
                        }
                    }
                    else if (this._treePanel) 
                    {
                        this._treePanel.updateBuildInfoPanel(this._structureInfo);
                    }
                }
                else if (this._hallPanel) 
                {
                    this._hallPanel.updateBuildInfoPanel(this._structureInfo);
                }
                loc1 = this.getStructureIndexByType(this._structureInfo.type);
                this._buildingListPanel.dataProvider.replaceItem(this._structureInfo, loc1);
                this._buildingListPanel.invalidateItemAt(loc1);
            }
            return;
        }

        /* internal  */getStructureIndexByType(arg1: EGuildStructureType): int
        {
            var loc1=0;
            var loc3=null;
            var loc2=this._buildingListPanel.dataProvider.toArray();
            var loc4=0;
            while (loc4 < loc2.length) 
            {
                if ((loc3 = loc2[loc4] as SGuildStructureInfo).type == arg1) 
                {
                    loc1 = loc4;
                }
                ++loc4;
            }
            return loc1;
        }

        /* internal */ /* var */_listBg: ScaleBitmap;

        /* internal */ /* var */_buildingListPanel: TilePanel;

        /* internal */ /* var */_buildingNumTip: Object /* flash.text.TextField */;

        /* internal */ /* var */_hallPanel: HallDetailPanel;

        /* internal */ /* var */_treePanel: AuraTreePanel;

        /* internal */ /* var */_shopPanel: ShopDetailPanel;

        /* internal */ /* var */_warehousePanel: WarehouseDetailPanel;

        /* internal */ /* var */_cashboxPanel: CashboxDetailPanel;

        /* internal */ /* var */_animalPanel: AnimalPanel;

        /* internal */ /* var */_schoolPanel: SchoolPanel;

        /* internal */ /* var */_pasturePanel: PasturePanel;

        /* internal */ /* var */_descText: Object /* flash.text.TextField */;

        /* internal */ /* var */_mainView: View;

        /* internal */ /* var */_backupView: View;

        /* internal */ /* var */_structureInfo: SGuildStructureInfo;
    }
